package com.example.abooktest;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

public class ContactsAdpater extends BaseAdapter {
        
        @SuppressWarnings("unused")
		private Context context;
        private ArrayList<Contact> items;
        private LayoutInflater inflater;
        private int layout;
        
        public ContactsAdpater(Context _context, int _layout, ArrayList<Contact> _items) {
                //super(context, items);
                //this.context = _context;
                //this.layout = _layout;
                //this.items = _items;
                context = _context;
                layout = _layout;
                items = _items;
                inflater = (LayoutInflater)_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
        
        @Override
        public int getCount() {
                  return items.size();
        }
        @Override
        public Object getItem(int position) {
                  return items.get(position);
        }
        @Override
        public long getItemId(int position) {
                  return position;
        }
        
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

                if ( convertView == null ) {
                        convertView = inflater.inflate(layout, parent, false);
                }
                
                // 현재의 position을 가지고 item을 가져온다. item은 이름과 전화번호가 들어있다.
                Contact temp = items.get(position);

                if ( temp != null ){
                        // 2개의 텍스트뷰를 셋팅해준다.
                        TextView textName = (TextView)convertView.findViewById(R.id.textName);
                        TextView textPhone = (TextView)convertView.findViewById(R.id.textPhone);
                        
                        // 셋팅한 텍스트뷰의 텍스트에 이름과 전화번호를 넣어준다.
                        textName.setText(temp.getName());
                        textPhone.setText(temp.getPhone());
                }
                
                CheckBox chkBox = (CheckBox)convertView.findViewById(R.id.checkBox1);
                chkBox.setClickable(false);
                chkBox.setChecked(items.get(position).isChecked);
                
                
                return convertView;             
        }
        

}